package android.slc.amaputils;

import android.content.Context;
import android.location.Location;
import android.slc.commonlibrary.subutil.CoordinateUtils;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;

/**
 * @author slc
 * @date 2020-09-09 16:27
 */
public class AMapLocationUtils {

    public static void init(Context context) {
        AMapLocationClient.updatePrivacyShow(context, true, true);
        AMapLocationClient.updatePrivacyAgree(context, true);
    }

    public static Location aMapLocationToLocation(AMapLocation aMapLocation) {
        Location location = new Location(aMapLocation);
        double[] locationData = CoordinateUtils.gcj02ToWGS84(aMapLocation.getLongitude(), aMapLocation.getLatitude());
        location.setLongitude(locationData[0]);
        location.setLatitude(locationData[1]);
        return location;
    }

    public static double[] locationStr2Location(String locationStr) {
        String[] locationStrArray = locationStr.split(",");
        return new double[]{Double.parseDouble(locationStrArray[0]), Double.parseDouble(locationStrArray[1])};
    }
}
